package com.budwk.app.sqfwV2.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.common.config.AppException;
import com.budwk.app.sqfw.component.CommonComponent;
import com.budwk.app.sqfw.component.CommunityStreetComponent;
import com.budwk.app.sqfw.constants.CommonConstants;
import com.budwk.app.sqfw.constants.DictConstants;
import com.budwk.app.sqfw.enums.DownLoadFileNameEnum;
import com.budwk.app.sqfw.enums.SqfwFormSummaryFieldEnum;
import com.budwk.app.sqfw.enums.SupportBusinessTypeEnum;
import com.budwk.app.sqfw.models.Sqfw_formSummary;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfw.models.Sqfw_form_summary_pdf;
import com.budwk.app.sqfw.services.SqfwCompleteflowService;
import com.budwk.app.sqfw.services.SqfwFormSummaryPdfService;
import com.budwk.app.sqfw.services.SqfwFormsummaryNewService;
import com.budwk.app.sqfw.vo.GenerateExcelUrlVO;
import com.budwk.app.sqfw.vo.Sqfw_formSummaryForAdminVO;
import com.budwk.app.sqfwDoc.bo.ExcelCreateConfig;
import com.budwk.app.sqfwDoc.dto.TemplateCodeUpdateDTO;
import com.budwk.app.sqfwV2.component.*;
import com.budwk.app.sqfwV2.dto.dto.SqfwShopBaseInfoDTO;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.DownExcelLedgerReqVo;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.DownFileTypesResVo;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.FormSummaryNewQueryReqVo;
import com.budwk.app.sqfwV2.dto.entity.SqfwShopsBaseInfo;
import com.budwk.app.sqfwV2.service.DayingRoadService;
import com.budwk.app.sqfwV2.service.ShopsBaseInfoService;
import com.budwk.app.sys.models.Sys_dict;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.SysDictService;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import com.budwk.starter.common.exception.BaseException;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.security.utils.SecurityUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.sql.Criteria;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.dao.util.cri.Static;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@IocBean
public class DayingRoadServiceImpl implements DayingRoadService {

    @Inject
    private FireSafetyOnDayingRoadExcelService dayingRoadExcelService;
    @Inject
    private FireSafetyOnDayingRoadPdfService dayingRoadPdfService;
    @Inject
    private SqfwFormsummaryNewService sqfwFormsummaryNewService;
    @Inject
    private SqfwFormSummaryPdfService sqfwFormSummaryPdfService;
    @Inject
    private SysDictService sysDictService;
    @Inject
    private SqfwCompleteflowService sqfwCompleteflowService;
    @Inject
    private ShopsBaseInfoService shopsBaseInfoService;
    @Inject
    private SysUserService sysUserService;
    @Inject
    private ShopsComponent shopsComponent;

    @Inject
    private SummarySafetyCommponent summarySafetyCommponent;

    /**
     * @return
     */
    @Override
    public Result<?> downExcelLedger(DownExcelLedgerReqVo reqVo) {
        List<ExcelCreateConfig> excelConfigList = CommonComponent.getExcelConfigList(reqVo);
        List<Sqfw_formSummary_new> list = new ArrayList<>();
        if (CollectionUtil.isEmpty(reqVo.getSqfwIds())) {
            if (!reqVo.isDownTemplate()) {
                list = CommonComponent.querySummarys(null, SupportBusinessTypeEnum.SAFETY_CHECK.getName());
                if (CollectionUtil.isEmpty(list)) {
                    return Result.success();
                }
            }
        }
        // 特殊情况 pdf下载
        List<GenerateExcelUrlVO> generateExcelUrlVOS = dayingRoadExcelService.downExcelLedger(reqVo, excelConfigList, SecurityUtil.getUserId(), list);
        return Result.data(generateExcelUrlVOS);
    }

    @Override
    public void submitData(TemplateCodeUpdateDTO dto) {
        // 初始创建任务
        summarySafetyCommponent.createOneTask(dto, "1", SupportBusinessTypeEnum.SAFETY_CHECK.getName());
        dayingRoadPdfService.generatePdfAndMessage(SecurityUtil.getUserId(), dto);
    }

    @Override
    public Result<?> listByConditionKey(String placeName, String content, String type) {
        List<Sqfw_formSummary_new> list = sqfwFormsummaryNewService.findByPlaceName(content, type);
        return Result.data(list);
    }

    @Override
    public Result<List<DownFileTypesResVo>> listDownFileTypes(String sqfwId) {
        try {
            List<Sqfw_formSummary_new> list = null;
            if (StringUtils.isEmpty(sqfwId)) {
                list = CommonComponent.querySummarys(null, SupportBusinessTypeEnum.SAFETY_CHECK.getName());
            } else {
                list = sqfwFormsummaryNewService.queryBySqfwIdAndType(sqfwId, SupportBusinessTypeEnum.SAFETY_CHECK.getName());
            }
            List<DownFileTypesResVo> resVos = DayingRoadPdfComponent.generateFiles(list);
            return Result.data(resVos);
        } catch (Exception e) {
            log.error("listDownFileTypes error: ", e);
            throw new AppException("数据异常，请联系系统管理员！");
        }
    }

    @Override
    public Result<?> listAdminByPage(FormSummaryNewQueryReqVo reqVo) {
        Criteria cri = Cnd.cri();
        SqlExpressionGroup criSql = cri.where();
        criSql.andEquals(Sqfw_formSummaryForAdminVO::getType, SupportBusinessTypeEnum.SAFETY_CHECK.getName());
        // 存在隐患()

        // 违规住人 是否住人 accommodatePeople.residentialType
        if (StringUtils.isNotEmpty(reqVo.getResidentialType())) {
            criSql.and(new Static("param_data->'accommodatePeople'->>'residentialType'='" + reqVo.getResidentialType() + "'"));
        }
        // 检查情况
        if (StringUtils.isNotEmpty(reqVo.getCheckStatus())) {
            criSql.andEquals(Sqfw_formSummaryForAdminVO::getCheckStatus, reqVo.getCheckStatus());
        }
        // 检查时间
        String queryTime = reqVo.getQueryTime();
        if (StringUtils.isNotBlank(queryTime)) {
            String[] queryTimes = queryTime.split(",");
            LocalDateTime startQueryTime = CommunityStreetComponent.handleStartQueryTime(LocalDateTimeUtil.parse(queryTimes[0]));
            LocalDateTime endQueryTime = CommunityStreetComponent.handleEndQueryTime(LocalDateTimeUtil.parse(queryTimes[1]));
            criSql.andBetween(Sqfw_formSummary::getFillDate, startQueryTime, endQueryTime);
        }
        Pagination pagination = sqfwFormsummaryNewService.listPage(reqVo.getPageNo(), reqVo.getPageSize(), cri);
        return Result.data(pagination);
    }

    @Override
    public Result<?> reGeneratePDF(String sqfwFlowId) {
        dayingRoadPdfService.reGeneratePDF(sqfwFlowId);
        return Result.success();
    }

    @Override
    public void changeCloseDown(String id) {
        Sqfw_formSummary_new sqfwFormSummary = sqfwFormsummaryNewService.fetch(id);
        if (ObjectUtil.isEmpty(sqfwFormSummary)) {
            throw new BaseException("id无法查询到关联数据");
        }
        sqfwFormSummary.setCheckStatus(SqfwFormSummaryFieldEnum.CHECK_STATUS_CLOSED.getCode());
        sqfwFormSummary.setUpdateDate(new Date()).setUpdateBy(SecurityUtil.getUserId()).setUpdateUserName(SecurityUtil.getUserUsername());
        sqfwFormsummaryNewService.update(sqfwFormSummary);

        // 修改商铺表状态
        String shopsBaseInfoId = sqfwFormSummary.getShopsBaseInfoId();
        if (StringUtils.isNotEmpty(shopsBaseInfoId)) {
            SqfwShopsBaseInfo shopsBaseInfo = shopsBaseInfoService.fetch(shopsBaseInfoId);
            shopsBaseInfo.setShopStatus(SqfwFormSummaryFieldEnum.CHECK_STATUS_CLOSED.getCode());
            shopsBaseInfoService.updateIgnoreNull(shopsBaseInfo);
        }
    }

    @Override
    public void downPdfTemplate(HttpServletResponse response) {
        String fileName = DownLoadFileNameEnum.SAFETY_INVESTIGATE_RENOVATE.getName() + ".pdf";
        String filepath = CommonFormOfficeUtils.getTemplatePathByOS("sqfwV2/daYingLu/template/dayingRoadSafeTemplate.pdf");
        // 下载文件
        CommonComponent.downFile(response, filepath, fileName);
    }

    @Override
    public void downWordTemplate(HttpServletResponse response) {
        String fileName = DownLoadFileNameEnum.SAFETY_INVESTIGATE_RENOVATE.getName() + ".docx";
        String filepath = CommonFormOfficeUtils.getTemplatePathByOS("sqfwV2/daYingLu/template/dayingRoadSafeTemplate.docx");
        // 下载文件
        CommonComponent.downFile(response, filepath, fileName);
    }

    @Override
    public Result<?> listShopByPage(SqfwShopBaseInfoDTO baseInfo) {
        Cnd cnd = Cnd.NEW();
        SqlExpressionGroup sqlGroup = cnd.where();
        if (StringUtils.isNotEmpty(baseInfo.getShopStatus())) {
            sqlGroup.andEquals(SqfwShopsBaseInfo::getShopStatus, baseInfo.getShopStatus());
        }
        if (StringUtils.isNotEmpty(baseInfo.getInspectionSituation())) {
            sqlGroup.andEquals(SqfwShopsBaseInfo::getInspectionSituation, baseInfo.getInspectionSituation()).andNotEquals(SqfwShopsBaseInfo::getShopStatus, SqfwFormSummaryFieldEnum.CHECK_STATUS_CLOSED.getCode());
            ;
        }
        if (StringUtils.isNotEmpty(baseInfo.getQueryContent())) {
            SqlExpressionGroup pSql = Cnd.exps(SqfwShopsBaseInfo::getPlaceName, "like", "%" + baseInfo.getQueryContent() + "%");
            SqlExpressionGroup aSql = Cnd.exps(SqfwShopsBaseInfo::getAddress, "like", "%" + baseInfo.getQueryContent() + "%");
            sqlGroup.and(pSql.or(aSql));
        }
        cnd.getOrderBy().desc(SqfwShopsBaseInfo::getFillDate);
        // 只查询安全排查的数据
        sqlGroup.andLike(SqfwShopsBaseInfo::getServiceType, SupportBusinessTypeEnum.SAFETY_CHECK.getCode());

        Sys_user sysUser = sysUserService.getUserById(SecurityUtil.getUserId());
        sqlGroup.andEquals(SqfwShopsBaseInfo::getProvince, sysUser.getProvince()).andEquals(SqfwShopsBaseInfo::getCity, sysUser.getCity()).andEquals(SqfwShopsBaseInfo::getDistrict, sysUser.getDistrict()).andEquals(SqfwShopsBaseInfo::getCounty, sysUser.getCounty());
        if (!CommonConstants.DIRECTLY_UNDER.equals(sysUser.getCommunity())) {
            sqlGroup.andEquals(SqfwShopsBaseInfo::getCommunity, sysUser.getCommunity());
        }
        // 1 不是已停业的其他数据
        List<SqfwShopsBaseInfo> list = shopsBaseInfoService.query(cnd);
        List<SqfwShopsBaseInfo> result = new ArrayList<>();
        List<SqfwShopsBaseInfo> result1 = new ArrayList<>(); // 不是已停业的其他数据
        List<SqfwShopsBaseInfo> result2 = new ArrayList<>(); // 已停业的数据
        // 已停业的放在最后面
        for (SqfwShopsBaseInfo shopsBaseInfo : list) {
            if (SqfwFormSummaryFieldEnum.CHECK_STATUS_CLOSED.getCode().equals(shopsBaseInfo.getShopStatus())) {
                result2.add(shopsBaseInfo);
                continue;
            }
            result1.add(shopsBaseInfo);
        }
        result.addAll(result1);
        result.addAll(result2);
        Pagination pagination = new Pagination();
        pagination.setList(result);
        pagination.setTotalCount(result.size());
        return Result.data(pagination);
    }

    @Override
    public Result<?> downPdfFile(DownExcelLedgerReqVo reqVo) {
        // 1 校验参数
        LanHudDuComponent.checkDownPdfFile(reqVo);
        if (reqVo.isDownTemplate()) {
            if (LanHudDuComponent.isLHDCity(SecurityUtil.getUserId())) {
                Sqfw_form_summary_pdf summaryPdf = LanHudDuComponent.downPdfTemplate(reqVo);
                log.info("downPdfFile info res: {}", JSONObject.toJSONString(summaryPdf));
                return Result.data(summaryPdf);
            }
        }
        List<Sqfw_formSummary_new> formSummaryNews = StringUtils.isEmpty(reqVo.getSqfwId()) ? CommonComponent.querySummarys(null, SupportBusinessTypeEnum.SAFETY_CHECK.getName()) : sqfwFormsummaryNewService.queryBySqfwIdAndType(reqVo.getSqfwId(), SupportBusinessTypeEnum.SAFETY_CHECK.getName());
        if (CollectionUtil.isEmpty(formSummaryNews)) {
            return Result.success();
        }
        if (LanHudDuComponent.isLHDCity(SecurityUtil.getUserId())) {
            Sqfw_form_summary_pdf summaryPdf = LanHudDuComponent.downPdfFile(formSummaryNews, reqVo);
            log.info("downPdfFile info res: {}", JSONObject.toJSONString(summaryPdf));
            return Result.data(summaryPdf);
        }
        return Result.success();
    }

    @Override
    public Result<Pagination> listCurrentUserShop(SqfwShopBaseInfoDTO baseInfo) {
        Cnd cnd = Cnd.NEW();
        SqlExpressionGroup sqlGroup = cnd.where();
        Sys_user user = CommonComponent.getCurrentUser();
        // 五级地址必须一致
        sqlGroup.andEquals(SqfwShopsBaseInfo::getProvince, user.getProvince()).andEquals(SqfwShopsBaseInfo::getCity, user.getCity()).andEquals(SqfwShopsBaseInfo::getDistrict, user.getDistrict()).andEquals(SqfwShopsBaseInfo::getCounty, user.getCounty()).andEquals(SqfwShopsBaseInfo::getCommunity, user.getCommunity());
        if (StringUtils.isNotEmpty(baseInfo.getQueryContent())) {
            SqlExpressionGroup pSql = Cnd.exps(SqfwShopsBaseInfo::getPlaceName, "like", "%" + baseInfo.getQueryContent() + "%");
            SqlExpressionGroup aSql = Cnd.exps(SqfwShopsBaseInfo::getAddress, "like", "%" + baseInfo.getQueryContent() + "%");
            sqlGroup.and(pSql.or(aSql));
        }
        if (StringUtils.isNotEmpty(baseInfo.getServiceType())) {
            sqlGroup.andLike(SqfwShopsBaseInfo::getServiceType, baseInfo.getServiceType());
        }
        if (StringUtils.isNotEmpty(baseInfo.getType())) {
            sqlGroup.andLike(SqfwShopsBaseInfo::getType, baseInfo.getType());
        }
        if (StringUtils.isNotEmpty(baseInfo.getPlaceType())) {
            sqlGroup.andLike(SqfwShopsBaseInfo::getPlaceType, baseInfo.getPlaceType());
        }
        if (StringUtils.isNotEmpty(baseInfo.getShopStatus())) {
            sqlGroup.andEquals(SqfwShopsBaseInfo::getShopStatus, baseInfo.getShopStatus());
        }
        if (StringUtils.isNotEmpty(baseInfo.getInspectionSituation())) {
            sqlGroup.andEquals(SqfwShopsBaseInfo::getInspectionSituation, baseInfo.getInspectionSituation());
        }
        // 人员类型
        if (StringUtils.isNotEmpty(baseInfo.getBussinessParamStr())) {
            cnd.and("(business_param::text)", "like", "%\"key\": \"" + baseInfo.getBussinessParamStr() + "\"%");
        }

        // checkStatus 3已经超时 1未超时
        String minDate = DateUtil.format(DateUtil.offsetDay(DateUtil.beginOfDay(new Date()), -30), "yyyy-MM-dd");
        String minDateOpera;
        if (baseInfo.getCheckStatus().equals("1")) {
            minDateOpera = ">=";
        } else {// 已超时
            minDateOpera = "<";
        }

        // 首先查询该社区已经进行检查过的商铺信息
        Cnd allShopCheckFormSummaryCND = Cnd.NEW();
        allShopCheckFormSummaryCND.and(Sqfw_formSummary_new::getProvince, "=", user.getProvince());
        allShopCheckFormSummaryCND.and(Sqfw_formSummary_new::getCity, "=", user.getCity());
        allShopCheckFormSummaryCND.and(Sqfw_formSummary_new::getDistrict, "=", user.getDistrict());
        allShopCheckFormSummaryCND.and(Sqfw_formSummary_new::getCounty, "=", user.getCounty());
        allShopCheckFormSummaryCND.and(Sqfw_formSummary_new::getCommunity, "=", user.getCommunity());
        allShopCheckFormSummaryCND.and(Sqfw_formSummary_new::getType, "=", SupportBusinessTypeEnum.getNameByCode(baseInfo.getServiceType()));
        allShopCheckFormSummaryCND.groupBy(Sqfw_formSummary_new::getShopsBaseInfoId);
        List<Sqfw_formSummary_new> allCheckShopDataList = sqfwFormsummaryNewService.query("shopsBaseInfoId$", allShopCheckFormSummaryCND);
        Set<String> allCheckShopIdSet = allCheckShopDataList.stream().map(Sqfw_formSummary_new::getShopsBaseInfoId).collect(Collectors.toSet());

        // 需要按照类型查询formSummary表中已经超时的数据，然后得到相应的店铺id
        Cnd checkTimeOutFormSummaryCND = Cnd.NEW();
        checkTimeOutFormSummaryCND.and(Sqfw_formSummary_new::getProvince, "=", user.getProvince());
        checkTimeOutFormSummaryCND.and(Sqfw_formSummary_new::getCity, "=", user.getCity());
        checkTimeOutFormSummaryCND.and(Sqfw_formSummary_new::getDistrict, "=", user.getDistrict());
        checkTimeOutFormSummaryCND.and(Sqfw_formSummary_new::getCounty, "=", user.getCounty());
        checkTimeOutFormSummaryCND.and(Sqfw_formSummary_new::getCommunity, "=", user.getCommunity());
        checkTimeOutFormSummaryCND.and(Sqfw_formSummary_new::getType, "=", SupportBusinessTypeEnum.getNameByCode(baseInfo.getServiceType()));
        checkTimeOutFormSummaryCND.and(Sqfw_formSummary_new::getFillDate, "<", minDate);
        List<Sqfw_formSummary_new> checkOutTimeSummaryList = sqfwFormsummaryNewService.query("shopsBaseInfoId$", checkTimeOutFormSummaryCND); // 这些店铺的检查肯定是已经超时了
        Set<String> checkOutTimeShopIdSet = checkOutTimeSummaryList.stream().map(Sqfw_formSummary_new::getShopsBaseInfoId).collect(Collectors.toSet()); // 这些店铺肯定是已经超时了的

        // 查询已经检查过的未超时的数据
        Cnd checkTimeInFormSummaryCND = Cnd.NEW();
        checkTimeInFormSummaryCND.and(Sqfw_formSummary_new::getProvince, "=", user.getProvince());
        checkTimeInFormSummaryCND.and(Sqfw_formSummary_new::getCity, "=", user.getCity());
        checkTimeInFormSummaryCND.and(Sqfw_formSummary_new::getDistrict, "=", user.getDistrict());
        checkTimeInFormSummaryCND.and(Sqfw_formSummary_new::getCounty, "=", user.getCounty());
        checkTimeInFormSummaryCND.and(Sqfw_formSummary_new::getCommunity, "=", user.getCommunity());
        checkTimeInFormSummaryCND.and(Sqfw_formSummary_new::getType, "=", SupportBusinessTypeEnum.getNameByCode(baseInfo.getServiceType()));
        checkTimeInFormSummaryCND.and(Sqfw_formSummary_new::getFillDate, ">=", minDate);
        List<Sqfw_formSummary_new> checkTimeInSummaryList = sqfwFormsummaryNewService.query("shopsBaseInfoId$", checkTimeInFormSummaryCND); // 这些店铺的检查肯定是已经超时了
        Set<String> checkTimeInShopIdSet = checkTimeInSummaryList.stream().map(Sqfw_formSummary_new::getShopsBaseInfoId).collect(Collectors.toSet()); // 这些店铺肯定是已经超时了的


        // wzy 2024-8-27 针对店铺已超时未超时问题修改
        // 巡查状态 已经超时，未超时
        if (StringUtils.isNotBlank(baseInfo.getCheckStatus())) {
            SqlExpressionGroup checkStatusGroup = Cnd.NEW().where();

            Set<String> compareShopIdSet;
            if (baseInfo.getCheckStatus().equals("1")) {
                compareShopIdSet = checkTimeInShopIdSet;
            } else {
                compareShopIdSet = checkOutTimeShopIdSet;
            }

            if (!allCheckShopIdSet.isEmpty()) {
                checkStatusGroup.and(SqfwShopsBaseInfo::getId, "in", compareShopIdSet).or(Cnd.NEW().where().and(SqfwShopsBaseInfo::getId, " not in ", allCheckShopIdSet).and(SqfwShopsBaseInfo::getCreateDate, minDateOpera, LocalDateTimeUtil.parse(minDate, "yyyy-MM-dd")));
            } else {
                checkStatusGroup.and(SqfwShopsBaseInfo::getId, "in", compareShopIdSet).or(Cnd.NEW().where().and(SqfwShopsBaseInfo::getCreateDate, minDateOpera, LocalDateTimeUtil.parse(minDate, "yyyy-MM-dd")));
            }
            cnd.and(checkStatusGroup);
        }

        // wzy 2024-08-27
        // 经营状态
        if (StringUtils.isNotBlank(baseInfo.getStatus())) {
            if (baseInfo.getStatus().equals("3")) {
                // 查询停业的店铺
                cnd.and(SqfwShopsBaseInfo::getShopStatus, "=", "3");
            } else {
                // 查询未停业的店铺
                cnd.and(SqfwShopsBaseInfo::getShopStatus, "!=", "3");
            }
        }

        cnd.getOrderBy().desc(SqfwShopsBaseInfo::getCreateDate);// 按照创建时间降序
        Pagination pagination = shopsBaseInfoService.listPage(baseInfo.getPageNo(), baseInfo.getPageSize(), cnd);
        shopsComponent.initUpdateAddress(pagination.getList(SqfwShopsBaseInfo.class));
        List<SqfwShopsBaseInfo> list = pagination.getList(SqfwShopsBaseInfo.class);
        log.info("listCurrentUserShop res data: {}", JSONObject.toJSONString(list));
        if (CollectionUtil.isEmpty(list)) {
            return Result.data(pagination);
        }
        // 處理导入数据 主要经营范围
        List<Sys_dict> dicts = new ArrayList<>();
        List<Sys_dict> dict1 = sysDictService.getSubListByCode(DictConstants.MAIN_BUSINESS_SCOPE);
        if (CollectionUtil.isNotEmpty(dict1)) {
            dicts.addAll(dict1);
        }
        List<Sys_dict> dict2 = sysDictService.getSubListByCode(DictConstants.MAIN_BUSINESS_SCOPE_SAFETY);
        if (CollectionUtil.isNotEmpty(dict2)) {
            dicts.addAll(dict2);
        }
        for (SqfwShopsBaseInfo s : list) {

            String shopId = s.getId();
            s.setInspectionSituation("1");  // 默认为未超时
            if (checkOutTimeShopIdSet.contains(shopId) || checkTimeInShopIdSet.contains(shopId)) {
                if (checkOutTimeShopIdSet.contains(shopId)) s.setInspectionSituation("3");
            } else if (s.getCreateDate().isBefore(LocalDateTimeUtil.parse(minDate, "yyyy-MM-dd"))) {
                s.setInspectionSituation("3");
            }

            if (StringUtils.isEmpty(s.getMainBusinessScope())) {
                continue;
            }
            if (SupportBusinessTypeEnum.SAFETY_CHECK.getName().equals(s.getType())) {
                Optional<Sys_dict> optional = dicts.stream().filter(e -> e.getName().equals(s.getMainBusinessScope())).findFirst();
                if (optional.isPresent()) {
                    s.setMainBusinessScope(optional.get().getCode());
                    shopsBaseInfoService.updateIgnoreNull(s);
                }
            }
        }
        ShopsComponent.clearLabel(list, baseInfo.getType());
        log.info("listCurrentUserShop last res data: {}", JSONObject.toJSONString(list));
        return Result.data(pagination);
    }
}
